package com.Image.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.Image.service.uploadImageService;


/**
 * 过滤上传图片
 * @author jiwei
 *
 */
@Controller
@RequestMapping(value="/upload")
public class uploadImageController {
	Logger logger = Logger.getLogger(uploadImageController.class);
	@Autowired
	private uploadImageService uploadservice;
	
	
	/**
	 * 上传图片
	* @Title: getUserinfo 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return ModelAndView    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月20日 下午4:05:40
	 */
	@RequestMapping(value = "/readImage")
	@ResponseBody
	public String  getUserinfo(HttpServletRequest request) {
		String reult=uploadservice.readImage(request);
		return reult;
	}
	
	/**
	 * 获取图集
	* @Title: getAtlas 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return ModelAndView    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月20日 下午4:05:29
	 */
	@RequestMapping(value="/getAtlas")
	public ModelAndView getAtlas(HttpServletRequest request){
		ModelAndView mv = uploadservice.getAtlas(request);
		List<Map<String, Object>> atlastagList=uploadservice.getTagList();
		mv.addObject("atlastagList", atlastagList);
		return mv;
	}
	
	/**
	 * 获取每个图集下的所有图片
	* @Title: getAllinfo 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return ModelAndView    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月20日 下午5:18:53
	 */
	@RequestMapping(value="/getAllinfo")
	public ModelAndView getAllinfo(HttpServletRequest request){
		String imageCode=request.getParameter("imagecode");
		ModelAndView mv = uploadservice.getAllinfo(request,imageCode);
		return mv;
	}
	
	/**
	 * 下架图集
	* @Title: deleteImageatlas 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return String    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月22日 下午4:16:57
	 */
	@RequestMapping(value="/deleteImageatlas")
	@ResponseBody
	public Map<String, Object> deleteImageatlas(HttpServletRequest request){
		Map<String, Object> reposemap=new HashMap<String,Object>();
		String  atlasCodes=request.getParameter("atlasCodes");
		String czcode=request.getParameter("czcode");
		int num=uploadservice.deleteImages(atlasCodes,czcode);
		if(num>0){
			reposemap.put("state","success");	
		}else{
			reposemap.put("state","error");
		}
		return reposemap;
	}
	/**
	 * 删除单个图片
	* @Title: deleteImagebyOne 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return Map<String,Object>    
	* @throws 
	* @author kiwishang 
	* @date 2018年1月3日 下午2:56:05
	 */
	@RequestMapping(value="/deleteImagebyOne")
	@ResponseBody
	public Map<String, Object> deleteImagebyOne(HttpServletRequest request){
		Map<String, Object> reposemap=new HashMap<String,Object>();
		String  deletekey=request.getParameter("deletekey");
    	int num=uploadservice.deleteImagebyOne(deletekey);
		if(num>0){
			reposemap.put("state","success");	
		}else{
			reposemap.put("state","error");
		}
		return reposemap;
	}
	
	
	
	
	/**
	 * 展示修改图集名称框
	* @Title: showNameDiv 
	* @Description: TODO
	* @param @return    
	* @return ModelAndView    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月22日 下午5:22:23
	 */
	@RequestMapping(value="/showNameDiv")
	public ModelAndView showNameDiv(HttpServletRequest request){
		String tagflag=request.getParameter("tagflag");
		String jspurl="";
		if(tagflag.equals("tag1")){
			jspurl="/view/showNameDiv";
		}else if(tagflag.equals("tag2")){
			jspurl="/view/showTagNameDiv";
		}else {
			jspurl="/view/showPrice";
		}
		ModelAndView mView=new ModelAndView(jspurl);
		if(tagflag.equals("tag2")){
			//查出所有的标签
			List<Map<String,Object>> taglist=uploadservice.getTagList();
			mView.addObject("tagList", taglist);
		}
		return mView;
	}
	
	/**
	 * 修改图集名称
	* @Title: updateAtlasName 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return Map<String,Object>    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月22日 下午6:03:38
	 */
	@RequestMapping(value="/updateAtlasName")
	@ResponseBody
	public Map<String, Object> updateAtlasName(HttpServletRequest request){
		Map<String, Object> reposemap=new HashMap<String,Object>();
		String  dataid=request.getParameter("dataid");
		String updatname=request.getParameter("updatname");
		int num=uploadservice.updateAtlasName(dataid,updatname);
		if(num>0){
			reposemap.put("state","success");	
		}else{
			reposemap.put("state","error");
		}
		return reposemap;
	}
	/**
	 * 修改标签
	* @Title: updateAtlasTag 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return Map<String,Object>    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月25日 下午3:11:00
	 */
	@RequestMapping(value="/updateAtlasTag")
	@ResponseBody
	public Map<String, Object> updateAtlasTag(HttpServletRequest request){
		Map<String, Object> reposemap=new HashMap<String,Object>();
		String  dataid=request.getParameter("dataid");
		String tagNames=request.getParameter("atlastags");
		int num=uploadservice.updateAtlasTag(dataid,tagNames);
		if(num>0){
			reposemap.put("state","success");	
		}else{
			reposemap.put("state","error");
		}
		return reposemap;
	}

	@RequestMapping(value="/updateAtlasPrice")
	@ResponseBody
	public Map<String, Object> updateAtlasPrice(HttpServletRequest request){
		Map<String, Object> reposemap=new HashMap<String,Object>();
		String  dataid=request.getParameter("dataid");
		String atlasPrice=request.getParameter("atlasPrice");
		int num=uploadservice.updateAtlasPrice(dataid,atlasPrice);
		if(num>0){
			reposemap.put("state","success");	
		}else{
			reposemap.put("state","error");
		}
		return reposemap;
	}
	
	/**
	 * 设置首页轮播图
	* @Title: bannerSet 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return ModelAndView    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月26日 下午2:09:36
	 */
	@RequestMapping(value="/bannerSet")
	public ModelAndView bannerSet(HttpServletRequest request){
		ModelAndView mv = uploadservice.bannerSet();
		return mv;
	}
	
	/**
	 * 设置轮播图
	* @Title: saveBanner 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return Map<String,Object>    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月27日 上午10:40:11
	 */
	@RequestMapping(value="/saveBanner")
	@ResponseBody
	public Map<String, Object> saveBanner(HttpServletRequest request){
		Map<String, Object> reposemap=new HashMap<String,Object>();
		String  ischeckedimg=request.getParameter("ischeckedimg");
		int num=uploadservice.saveBanner(ischeckedimg);
		if(num>0){
			reposemap.put("state","success");	
		}else{
			reposemap.put("state","error");
		}
		return reposemap;
	}
	
	
	
	/**
	 * 展示版本控制的页面
	* @Title: showAppversion 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return ModelAndView    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月27日 上午10:48:14
	 */
	@RequestMapping(value="/showAppversion")
	public ModelAndView showAppversion(HttpServletRequest request){
		ModelAndView mv = new ModelAndView("/view/appVersion");
		return mv;
	}
	
	
	
	/**
	 * app版本控制
	* @Title: appVersionset 
	* @Description: TODO
	* @param @param request
	* @param @return    
	* @return Map<String,Object>    
	* @throws 
	* @author kiwishang 
	* @date 2017年12月27日 上午10:42:08
	 */
	@RequestMapping(value="/appVersionset")
	@ResponseBody
	public Map<String, Object> appVersionset(HttpServletRequest request){
		Map<String, Object> reposemap=new HashMap<String,Object>();
		int num=uploadservice.appVersionset(request);
		if(num>0){
			reposemap.put("state","success");	
		}else{
			reposemap.put("state","error");
		}
		return reposemap;
	}
	
}
